import 'package:flutter/material.dart';
import 'SettingsPage.dart';
import 'WalletPage.dart';

class MePage extends StatelessWidget {
	final String title;

	MePage({Key key, @required this.title}) : super(key: key);

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				title: Text(title),
			),
			body: Container(
                padding: EdgeInsets.only(top: 16.0),
                color: Colors.grey[300],
                child: ListView(
                    children: <Widget>[
                        Container(
                            color: Colors.white,
                            child: ListTile(
                                leading: Image.asset(
                                    'assets/icons/avatar0.png',
                                    width: 50,
                                ),
                                title: Text('UserName'),
                                subtitle: Text('WeChat ID: 12345566dfdsfds'),
                                trailing: Icon(Icons.keyboard_arrow_right),
								onTap: () {
									Navigator.push(context, MaterialPageRoute(builder: (context) => ProfilePage()));
								},
                            ),
                        ),
                        Container(
                            color: Colors.white,
                            margin: EdgeInsets.only(top: 16.0),
                            child: ListTile(
                                leading: Icon(Icons.account_balance_wallet),
                                title: Text('Wallet'),
                                trailing: Icon(Icons.keyboard_arrow_right),
								onTap: () {
									Navigator.push(context, MaterialPageRoute(builder: (context) => WalletPage()));
								},
                            ),
                        ),
                        Container(
                            color: Colors.white,
                            margin: EdgeInsets.only(top: 16.0),
                            child: ListTile(
                                leading: Icon(Icons.account_balance_wallet),
                                title: Text('Favorites'),
                                trailing: Icon(Icons.keyboard_arrow_right),
                            ),
                        ),
                        Divider(
                            height: 1.0,
                            color: Colors.grey,
                        ),
                        Container(
                            color: Colors.white,
                            padding: EdgeInsets.only(top: 16.0),
                            child: ListTile(
                                leading: Icon(Icons.picture_in_picture),
                                title: Text('My Posts'),
                                trailing: Icon(Icons.keyboard_arrow_right),
                            ),
                        ),
                        Divider(
                            height: 1.0,
                            color: Colors.white,
                        ),
                        Container(
                            color: Colors.white,
                            padding: EdgeInsets.only(top: 16.0),
                            child: ListTile(
                                leading: Icon(Icons.credit_card),
                                title: Text('Cards & Offers'),
                                trailing: Icon(Icons.keyboard_arrow_right),
                            ),
                        ),
                        Divider(
                            height: 1.0,
                            color: Colors.white,
                        ),
                        Container(
                            color: Colors.white,
                            padding: EdgeInsets.only(top: 16.0),
                            child: ListTile(
                                leading: Icon(Icons.insert_emoticon),
                                title: Text('Sticker Gallery'),
                                trailing: Icon(Icons.keyboard_arrow_right),
                            ),
                        ),
                        Container(
                            color: Colors.white,
                            margin: EdgeInsets.only(top: 16.0),
                            child: ListTile(
                                leading: Icon(Icons.settings),
                                title: Text('Settings'),
                                trailing: Icon(Icons.keyboard_arrow_right),
								onTap: () {
									Navigator.push(context, MaterialPageRoute(builder: (builder) => SettingsPage()));
								},
                            ),
                        ),
                    ],
                ),
            ),
		);
	}
}

class ProfilePage extends StatelessWidget {

	ProfilePage({Key key}) : super(key: key);

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				title: Text('My Profile'),
			),
			body: Container(
				color: Colors.grey[300],
				padding: EdgeInsets.only(top: 16.0),
				child: ListView(
					children: <Widget>[
						Container(
							color: Colors.white,
							margin: EdgeInsets.only(bottom: 1.0),
							child: ListTile(
								title: Text('Profile Photo'),
								trailing: Image.asset(
									'assets/icons/avatar0.png',
									width: 50,
								),
								onTap: () {
									Navigator.push(context, MaterialPageRoute(builder: (context) => ProfilePhotoPage()));
								},
							),
						),
						Container(
							color: Colors.white,
							margin: EdgeInsets.only(bottom: 1.0),
							child: ListTile(
								title: Text('Name'),
								trailing: Container(
									child: Text('UserName'),
								),
								onTap: () {
									Navigator.push(context, MaterialPageRoute(builder: (context) => NameEditPage(name: 'UserName',)));
								},
							),
						),
						Container(
							color: Colors.white,
							margin: EdgeInsets.only(bottom: 1.0),
							child: ListTile(
								title: Text('WeChat ID'),
								trailing: Container(
									child: Text('1232fsfdseew'),
								),
							),
						),
						Container(
							color: Colors.white,
							margin: EdgeInsets.only(bottom: 1.0),
							child: ListTile(
								title: Text('My QR Code'),
								trailing: Container(
									child: Icon(Icons.keyboard_arrow_right),
								),
								onTap: () {
									Navigator.push(context, MaterialPageRoute(builder: (context) => QRCodePage()));
								},
							),
						),
						Container(
							color: Colors.white,
							margin: EdgeInsets.only(bottom: 1.0),
							child: ListTile(
								title: Text('More'),
								trailing: Container(
									child: Icon(Icons.keyboard_arrow_right),
								),
								onTap: () {
									Navigator.push(context, MaterialPageRoute(builder: (context) => MorePage()));
								},
							),
						),
					],
				),
			),
		);
	}
}

class ProfilePhotoPage extends StatelessWidget {

	ProfilePhotoPage({Key key}) :super(key: key);
	
	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				title: Text('Photo'),
			),	
			body: Container(
				color: Colors.black,
				child: Center(
					child: Image.asset(
						'assets/icons/avatar0.png'
					),
				),
			),
		);
	}
}

class NameEditPage extends StatefulWidget {

	final String name;

	NameEditPage({Key key, @required this.name}) : super(key: key);

	_NameEditPageState createState() {
		return _NameEditPageState();
	}
}

class _NameEditPageState extends State<NameEditPage> {
	
	TextEditingController _controller;

	@override
	void initState() {
		super.initState();
		_controller = TextEditingController();
		print(widget.name);
		_controller.text = widget.name;
		_controller.addListener(_nameEdit);
	}

	@override
	void dispose() {
		_controller.dispose();
		super.dispose();
	}

	_nameEdit() {
		setState(() {
			// _controller.text = '';
		});
	}

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				title: Text('Name'),
				actions: <Widget>[
					RaisedButton(
						color: Colors.blue,
						child: Text(
							'Done',
							style: TextStyle(
								color: Colors.green
							),
						),
						onPressed: () {
							Navigator.pop(context);
						},
					)
				],
			),
			body: Container(
				color: Colors.grey[300],
				margin: EdgeInsets.only(top: 16.0),
				child: TextField(
					autofocus: true,
					controller: _controller,
					decoration: InputDecoration(
						contentPadding: EdgeInsets.all(8.0)
					),
				),
			),
		);
	}
}

class QRCodePage extends StatelessWidget {

	QRCodePage({Key key}) : super(key: key);

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				title: Text('My QR Code'),
				actions: <Widget>[
					IconButton(
						icon: Icon(Icons.more_vert),
						onPressed: () {
							showModalBottomSheet(context: context, builder: (builder) => QRSheetPage());
							// ScaffoldState().showBottomSheet((builder) => QRSheetPage());
						},
					)
				],
			),
			body: Container(
				color: Colors.black,
				padding: EdgeInsets.only(left: 16.0, right: 16.0),
				child: Column(
					crossAxisAlignment: CrossAxisAlignment.center,
					mainAxisAlignment: MainAxisAlignment.center,
					children: <Widget>[
						Container(
							color: Colors.white,
							child: Column(
								children: <Widget>[
									ListTile(
										contentPadding: EdgeInsets.all(16.0),
										leading: Image.asset(
											'assets/icons/avatar0.png',
											width: 50,
										),
										title: Row(
											children: <Widget>[
												Text('UserName'),
												Icon(Icons.pregnant_woman)
											],
										),
										subtitle: Text(
											'Shenzhen, Guangdong',
											style: TextStyle(
												color: Colors.grey
											),
										),
									),
									Image.asset('assets/icons/avatar0.png',),
									Container(
										margin: EdgeInsets.only(top: 32.0, bottom: 16.0),
										child: Text(
											'Scan the QR code to add me on WeChat',
											style: TextStyle(
												color: Colors.grey
											),
										),
									)
								],
							)
						)
					],
				),
			),
		);
	}
}

class QRSheetPage extends StatefulWidget {

	QRSheetPage({Key key}) : super(key: key);

	@override
	_QRSheetPageState createState() => _QRSheetPageState();
}

class _QRSheetPageState extends State<QRSheetPage> {
	@override
	Widget build(BuildContext context) {
		return Column(
			mainAxisSize: MainAxisSize.min,
			children: <Widget>[
				ListTile(
					title: Center(
						child: Text('Change Style'),
					),
					onTap: () {
						print('Change Style');
						// 关闭modalSheet
						Navigator.pop(context);
					},
				),
				Divider(
					height: 1.0,
					color: Colors.grey,
				),
				ListTile(
					title: Center(
						child: Text('Save Image'),
					),
					onTap: () {
						print('Save Image');
						// 关闭modalSheet
						Navigator.pop(context);
					},
				),
				Divider(
					height: 1.0,
					color: Colors.grey,
				),
				ListTile(
					title: Center(
						child: Text('Scan QR Code'),
					),
					onTap: () {
						print('Scan QR Code');
						// 关闭modalSheet
						Navigator.pop(context);
					},
				),
				Divider(
					height: 1.0,
					color: Colors.grey,
				),
				ListTile(
					title: Center(
						child: Text('Reset QR Code'),
					),
					onTap: () {
						print('Reset QR Code');
						// 关闭modalSheet
						Navigator.pop(context);
					},
				),
				Divider(
					height: 16.0,
					color: Colors.grey,
				),
				ListTile(
					title: Center(
						child: Text('Cancel'),
					),
					onTap: () {
						// 关闭modalSheet
						Navigator.pop(context);
					},
				)
			],
		);
	}
}

class MorePage extends StatelessWidget {

	MorePage({Key key}) : super(key : key);

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				backgroundColor: Colors.blue,
			),
			body: Container(
				color: Colors.grey[300],
				padding: EdgeInsets.only(top: 16.0),
				child: ListView(
					children: <Widget>[
						Container(
							color: Colors.white,
							margin: EdgeInsets.only(bottom: 1.0),
							child: ListTile(
								title: Text('Gender'),
								trailing: Text('Male', style: TextStyle(color: Colors.grey),),
								onTap: () {
									Navigator.push(context, MaterialPageRoute(builder: (context) => ChooseGenderPage()));
								},
							),
						),
						Container(
							color: Colors.white,
							margin: EdgeInsets.only(bottom: 1.0),
							child: ListTile(
								title: Text('Region'),
								trailing: Text('Male', style: TextStyle(color: Colors.grey),),
							),
						),
						Container(
							color: Colors.white,
							margin: EdgeInsets.only(bottom: 1.0),
							child: ListTile(
								title: Text("What's Up"),
								trailing: Text('Male', style: TextStyle(color: Colors.grey),),
								onTap: () {
									Navigator.push(context, MaterialPageRoute(builder: (context) => SignTextPage()));
								},
							),
						),
					],
				),
			),
		);
	}
}

class ChooseGenderPage extends StatefulWidget {

	ChooseGenderPage({Key key}) : super(key: key);

	_ChooseGenderPageState createState() => _ChooseGenderPageState();
}

class _ChooseGenderPageState extends State<ChooseGenderPage> {
	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				backgroundColor: Colors.blue,
				title: Text('SettingsGender'),
			),
			body: Container(
				color: Colors.grey[300],
				child: ListView(
					children: <Widget>[
						Container(
							color: Colors.white,
							margin: EdgeInsets.only(bottom: 1.0),
							child: RadioListTile(
								title: Text('Male'),
								groupValue: 'Gender',
								value: 'Male',
								selected: true,
								onChanged: (dynamic) {
								},
							),
						),
						Container(
							color: Colors.white,
							child: RadioListTile(
								title: Text('FeMale'),
								groupValue: 'Gender',
								value: 'FeMale',
								onChanged: (dynamic) {
								},
							),
						)
					],
				),
			),
		);
	}
}

class SignTextPage extends StatefulWidget {
	SignTextPage({Key key}) : super(key: key);

	@override
	_SignTextPageState createState() => _SignTextPageState();
}

class _SignTextPageState extends State<SignTextPage> {
	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(
				title: Text("SettingsWhat'sUp"),
			),
			body: Container(
				color: Colors.grey[300],
				padding: EdgeInsets.only(top: 16.0),
				child: TextField(
					autofocus: true,
					maxLength: 25,
					maxLines: 3,
					decoration: InputDecoration(
						contentPadding: EdgeInsets.all(8.0)
					),
				),
			),
		);
	}
}